
var config = require("config");
var handler = require("handler");
cc.Class({
    extends: cc.Component,

    properties: {
        itemName: cc.Label,
        itemPrice: cc.Label,
    },

    init: function(sellItem) {
        if (sellItem.valid) {
            this.itemConfig = sellItem;
            this.itemName.string = "所有人：" + this.itemConfig.seller.substr(0, 5);
            this.itemPrice.string = this.itemConfig.weiValue + "ETH";
        } else {
            this.node.removeFromParent();
        }
    },

    onClickBuy: function() {
        var self = this;
        handler.buyProduct(this.itemConfig.transId, this.itemConfig.weiValue);

        // setTimeout(() => {
        //     self.checkBuyResult();
        // }, 1000);
        this.checkBuyResult();
    },

    checkBuyResult: function() {
        alert("购买成功，物品请等待仓库刷新");
        this.scheduleOnce(function() {
            handler.getPlayer();
        }, 1);
    }
})